package org.csc.sss.api.controller.base;

import com.google.common.collect.Lists;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.csc.sss.core.annontation.WebLog;
import org.csc.sss.core.dto.PersonDTO;
import org.csc.sss.core.enums.GenderEnum;
import org.csc.sss.core.model.*;
import org.csc.sss.util.Result;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Controller
@RequestMapping(value = "public")
public class PublicController extends BaseController {

//    @Autowired
//    private IdGenerator idGenerator;

    @WebLog("测试")
    @ResponseBody
    @RequestMapping(value = "logoutUrl")
    public Result<?> logoutUrl() {
        return super.ok(super.getUser());
    }

    @ResponseBody
    @RequestMapping(value = "failure")
    public Result<?> failure(@RequestParam(required = true) String msg) {
        return super.error(Result.ResultCode.ERROR, msg);
    }

    @RequestMapping(value = "sessionsView")
    public String sessionsView() {
        return "redirect:http://127.0.0.1:8890/login";
    }

    @RequestMapping(value = "test")
    public String test() {
        return "redirect:http://127.0.0.1:8889/public/aaa";
    }

    @ResponseBody
    @RequestMapping(value = "aaa")
    public Result<?> aaa() {
        return super.ok();
    }

    @ApiOperation("查询人列表-分页")
    @WebLog("查询人列表-分页")
    @GetMapping(value = "/page")
    @ResponseBody
    public Result<Page<PersonDTO>> listPagePerson(PersonDTO dto, @ApiParam("页数") Integer page, @ApiParam("每页大小") Integer seiz, @ApiParam("排序字段") String sortField) {

        return super.ok(super.personRepositoryImpl.findAll(dto, super.pageRequest(page, seiz, sortField, true)));
    }

    @ResponseBody
    @RequestMapping(value = "testUp")
    public Result<Person> testUp(PersonDTO dto) {


        return super.ok();
    }

    @ResponseBody
    @RequestMapping(value = "da")
    @WebLog
    public String da(String data) {
        return "测试aaa";
    }


    @ResponseBody
    @RequestMapping(value = "test1")
    public String test1() {
        log.info("info 测试");
        log.warn("warn 测试");
        log.debug("debug 测试");
        return "1111";
    }

    @ResponseBody
    @RequestMapping(value = "enum")
    public String genderEnum(GenderEnum genderEnum) {

        return genderEnum.getRemark();
    }

//    @ResponseBody
//    @RequestMapping(value = "getId")
//    public Result<?> getId() {
//        return super.ok(idGenerator.generateId().longValue());
//    }

}
